package com.example.testapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableArrayMap;
import androidx.databinding.ObservableField;

import android.os.Bundle;

import com.example.testapplication.bean.Start1;
import com.example.testapplication.bean.Start2;
import com.example.testapplication.databinding.ActivityBindingBinding;


public class xueJetpackDatabinding extends AppCompatActivity {


    private Start1 start1;
    private Start2 start2;
    ObservableArrayMap<String,Object> map;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_binding);
        //activityDataBindingBinding = DataBindingUtil.setContentView(this,R.layout.activity_databinding);
        // 设置数据
        ActivityBindingBinding binding = DataBindingUtil.setContentView(this,R.layout.activity_binding);
        binding.setStart1(start1 = new Start1("金城武",1000));
        binding.setAciton(new ButtonAction());

        binding.setStart2(start2 = new Start2(new ObservableField<>("古天乐"),new ObservableField<>(1001)));

        map = new ObservableArrayMap<String,Object>();
        map.put("name","樱木");
        map.put("fans",1000);
        //binding.setStart3(map)
        binding.setStart3(map);







    }

  public class ButtonAction{
     public void addFans(){
         int number = start1.getFans() +1;
         start1.setFans(number);
     }
     public void addFans2(){
         int number = start2.getFans().get()+1;
         start2.getFans().set(number);
     }

     public void addFans3(){
         int number = Integer.valueOf(map.get("fans").toString()) +1;
         map.put("fans",number);
     }

  }
}